//
//  ViewController.swift
//  Day06-JSONSwift
//
//  Created by 刘观华 on 2022/8/2.
//

import UIKit
import Alamofire
import HandyJSON
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        requestAPI()
        print(dataArray)
    }
    
    var dataArray:Array? = []
    
    func requestAPI(){
        let url = "https://jsonplaceholder.typicode.com/users"
        AF.request(url).response { response in
            if let res = response.data {
                let arr = try? JSONSerialization.jsonObject(with: res, options: .mutableContainers) as? Array<Any>
                if  let  a = arr {
                    for  dict  in a {
                        let dd = dict as? Dictionary<String, Any>
                        let picModel:PicModel? = PicModel.deserialize(from: dd, designatedPath:nil)
                        if let realModel = picModel {
                            print(realModel)
                            self.dataArray?.append(realModel)
                        }
                    }
                }
            }
            
        }
    }


}

